package com.saturn.action.sldb.emergency;

import java.util.ArrayList;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.saturn.app.web.IAction;
import com.saturn.app.web.IView;
import com.saturn.app.web.view.JspView;
import com.saturn.sldb.Emergency;
import com.saturn.sldb.TempSub;

public class QueryEmergencyAction implements IAction{
	@Override
	public IView execute(HttpServletRequest request,
			HttpServletResponse response) {
		String id = request.getParameter("id");
		String view = request.getParameter("view");
		String type= request.getParameter("type");
		
		Emergency vo = Emergency.get(id);
		List<TempSub> subs = new ArrayList<TempSub>();
		request.setAttribute("emergency", vo);
		if("2".equals(type)){
				if (vo != null) {
					subs = TempSub.getByPid(id);
				}
				request.setAttribute("emergency", vo);
				request.setAttribute("subs", subs);
				return new JspView("/app/sldb/approval/pending/edit.jsp");
		}else if("3".equals(type)){
			if (vo != null) {
				subs = TempSub.getByPid(id);
			}
			request.setAttribute("emergency", vo);
			request.setAttribute("subs", subs);
			return new JspView("/app/sldb/emergency/approval/edit.jsp");
		}else{
			if("ok".equals(view)){
				if(vo!=null){
					subs = TempSub.getByPid(id);
				}
				request.setAttribute("subs", subs);
				return new JspView("/app/sldb/emergency/approval/view.jsp");
			} else{
				
				if (vo != null) {
					subs = TempSub.getByPid(id);
				}
				request.setAttribute("emergency", vo);
				request.setAttribute("subs", subs);
				return new JspView("/app/sldb/emergency/apply/edit.jsp");
			}
		}
		
	}
		

	@Override
	public String requestMapping() {
		return "/app/sldb/emergency/query.action";
	}
}
